package com.isoftstone.plugin.freemark;

import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.util.PageData;

import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Created by admin on 16/4/15.
 */
public class MyFreeMarkView extends FreeMarkerView {

    private static final String CONTEXT_PATH = "base";
    private static final String CONTEXT_BASEPATH = "basePath";

    @Override
    protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
        model.put(CONTEXT_PATH, request.getContextPath());

       if("1".equals(BaseController.userContextPathFlag)){
           model.put(CONTEXT_BASEPATH,BaseController.baseContextPath);
           logger.info("IP========="+BaseController.baseContextPath);
       }else {
           model.put(CONTEXT_BASEPATH, request.getScheme() + "://"
                   + request.getServerName() + ":" + request.getServerPort()
                   + request.getContextPath() + "/");


           logger.info(
                   "IP================" + request.getScheme() + "://"
                           + request.getServerName() + ":" + request.getServerPort()
                           + request.getContextPath() + "/"

           );
       }

        logger.info("sessionid ======== " + request.getSession().getId());

        /**
         * auhtor wangjs
         * date   16/4/18 21:30
         *  把PD的内容转成Map
         */



//        List<HashMap<String,String>> aa = new ArrayList<HashMap<String,String>>();
//
//        HashMap<String, String> map = new HashMap<String, String>();
//
//        map.put("NAME", "CCCCC");
//        map.put("PWD", "ddddddd");
//
//        aa.add(map);
//
//        model.put("tt", aa);


        // model.put("msg", model.put);


        if (model.get("pd") != null) {
            //request.setAttribute("pd",((HashMap)(model.get("pd"))).entrySet());

            model.put("pd", (((PageData)(model.get("pd"))).getMap()));
            //request.getSession().setAttribute("pd",((HashMap)(model.get("pd"))).entrySet());

        }

        super.exposeHelpers(model, request);
    }
}
